<template>
	<view class="pagesbg">
		<!-- 头部 -->
		<view class="header_bar header_fixed header_main">
			<view class="header">
				<view class="header-goBack" @click="$tools.back(1)"></view>
				<view class="header-title">{{isChoose==2?'选择收款方式':'绑定收款信息'}}</view>
			</view> 
		</view> 
		<!-- 主体 -->
		<view class="setList">
			<view class="setList-wrapper">
				<!-- <view class="initNoData" v-if="idNoData == true">啊哦，暂无收款方式</view> -->
				<view class="setList-item" v-for="(item,index) in paymentList" :key="index"
				@tap.stop="goUrl(item.name,item.type)" > 
				<!-- v-if="item.isShow == 2" -->
					<view class="setList-item__left">
						<image v-if="item.type == 1" class="setList-item__icon" src="@/static/public/wechat.png" mode="widthFix"></image>
						<image v-if="item.type == 2" class="setList-item__icon" src="@/static/public/alipay.png" mode="widthFix"></image>
						<image v-if="item.type == 3" class="setList-item__icon" src="@/static/public/bank-1.png" mode="widthFix"></image>
						<view class="setList-item__name">{{ item.name }}</view>
					</view>
					<view class="setList-item__right">
						<view class="status" v-if="item.type == 1">{{ wechat == 1 ? '已' : '去' }}绑定</view>
						<view class="status" v-if="item.type == 2">{{ alipay == 1 ? '已' : '去' }}绑定</view>
						<view class="status" v-if="item.type == 3">{{ bank == 1 ? '已' : '去' }}绑定</view>
						<image class="next" src="@/static/public/icon-next.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components:{
		},
		data(){
			return{
				payList: [],
				wechat: '',
				wechatItem: {},
				alipay: '',
				alipayItem: {},
				bank: '',
				bankItem: {},
				idNoData: false,
				isChoose:'',
			}
		},
		computed:{
			paymentList(){
				return [
					{name: '微信',isShow: 2,type: 1,},
					{name: '支付宝',isShow: 2,type: 2,},
					{name: '银行卡',isShow: 2,type: 3,},
				]
			},
		},
		onLoad(options) {
			if(options.value1){
				this.backName = options.value1
			}
			if(options.value2){
				this.isChoose = options.value2
			}
		},
		onShow() {
			this.init();
		},
		// 下拉刷新
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 500);
		},
		methods: {
			init(){
				this.wechat = '';
				this.wechatItem = {};
				this.alipay = '';
				this.alipayItem = {};
				this.bank = '';
				this.bankItem = {};
				this.getAllUserPayment();
			},
			goUrl(name,type){
				if(type == 3){
					if(this.bank == 1){
						this.isGo(type)
					}else{
						uni.setStorageSync('chooseBank', JSON.stringify({type:''}));
					}
					this.$tools.jump('./addBank',name,encodeURIComponent(JSON.stringify(this.bankItem)));
				}else{
					if(type == 1){
						if(this.wechat == 1){
							this.isGo(type)
						}
						else{
							uni.setStorageSync('chooseBank', JSON.stringify({type:''}));
						}
						console.log("wechatItem：",this.wechatItem);
						this.$tools.jump('./paymentBind',name,encodeURIComponent(JSON.stringify(this.wechatItem)));
					}else if(type == 2){
						if(this.alipay == 1){
							this.isGo(type)
						}else{
							uni.setStorageSync('chooseBank', JSON.stringify({type:''}));
						}
						this.$tools.jump('./paymentBind',name,encodeURIComponent(JSON.stringify(this.alipayItem)));
					}
				}
			},
			isGo(type){
				// 返回提现页面
				if(this.isChoose ==2){
					const index = this.paymentListAll.findIndex(item=>item.type ==type)
					const item = index>-1?this.paymentListAll[index]:type
					console.log("item",item)
					uni.setStorageSync('chooseBank', JSON.stringify(item));
					return this.$tools.jump('/pages/balance/withdrawal',this.backName)
				}else{
					uni.setStorageSync('chooseBank', JSON.stringify({type:''}));
				}
			},
			getAllUserPayment() {
				var data = {};
				console.log("data：",data);
				this.$Ajax('/api/money/getWithdrawalBindInfo',data,res => {
						// if(JSON.stringify(res.data) == '[]' || (res.data.isWepay == 1 && res.data.isAlipay == 1 && res.data.isBank == 1 && res.data.isThird == 1 && res.data.isUsdt == 1)){
						// 		this.idNoData = true; 
						// }
						// this.paymentList.forEach((item,index) => {
						// 	if(index == 0){
						// 		this.$set(item,'isShow',res.data.isWepay);
						// 	}else if(index == 1){
						// 		this.$set(item,'isShow',res.data.isAlipay);
						// 	}else if(index == 2){
						// 		this.$set(item,'isShow',res.data.isBank);
						// 	}
						// })
						if(JSON.stringify(res.data) != '[]'){
							this.payList = res.data;
							this.payList.forEach((item,index) => {
								switch(item.type){
									case 1:
										this.wechat = 1;this.wechatItem = item;
										// this.$set(this.paymentList[0],'isShow',res.data.isWepay);
										return;
										break;
									case 2:
										this.alipay = 1;this.alipayItem = item;
										// this.$set(this.paymentList[1],'isShow',res.data.isAlipay);
										return;
										break;
									case 3:
										this.bank = 1;this.bankItem = item;
										// this.$set(this.paymentList[2],'isShow',res.data.isBank);
										return;
										break;
								}
							})
						}
						this.paymentListAll = res.data
						console.log("this.paymentList：",this.paymentList);
					}, err => {
					}, 'GET'
				)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.setList{
		padding:  0 0 74rpx;
		&-wrapper{
			margin: 20rpx 24rpx;
			background: #FFFFFF;
			border-radius: 12rpx;
		}
		&-item{
			@include flexBetween;
			padding: 20rpx 30rpx;
			&__left{
				@include flexLeft;
			}
			&__name{
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #000;
			}
			&__icon{
				width: 72rpx;
				height: 72rpx;
				margin-right: 16rpx;
			}
			&__right{
				@include flexRight;
				.status{
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: rgba(51,51,51,0.6);
				}
				.next{
					width: 20rpx;
					height: 20rpx;
					margin-left: 16rpx;
				}
			}
		}
	}
	
</style>